package jia.editor.processors;

import jia.core.GameStateManager;
import jia.core.InputProcessor;
import jia.core.Compass;
import jia.core.event.KeypressUiEvent;
import jia.core.event.UiEvent;
import jia.core.state.PlayerState;

import java.awt.event.KeyEvent;

/**
 * @author Alec Lanter
 */
public class EditorInputProcessor implements InputProcessor{
    protected GameStateManager gameState;
    
    /**
     * @see net.sf.jia.core.InputProcessor#registerGameState(net.sf.jia.core.GameStateManager)
     */
    public void registerGameState(GameStateManager gameState){
        this.gameState = gameState;
    }
    
    /**
     * @see net.sf.jia.core.InputProcessor#processUiEvent(net.sf.jia.framework.event.UiEvent)
     */
    public void processUiEvent(UiEvent evt){
        if(evt instanceof KeypressUiEvent) {
            PlayerState psm = gameState.getPlayerState();
            KeypressUiEvent evt2 = (KeypressUiEvent) evt;
            switch(evt2.getKeyCode()) {
                case KeyEvent.VK_UP:
                    psm.moveForward();
                    break;
                case KeyEvent.VK_DOWN:
                    psm.moveBackward();
                    break;
                case KeyEvent.VK_LEFT:
                    psm.setFacing(Compass.add(psm.getFacing(), Compass.WEST));
                    break;
                case KeyEvent.VK_RIGHT:
                    psm.setFacing(Compass.add(psm.getFacing(), Compass.EAST));
                    break;
            }
        }
    }
}
